/*
 * Project: Sudoku Explainer
 * Copyright (C) 2006-2007 Nicolas Juillerat
 * 
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.rules.chaining;

import java.io.Serializable;

import com.onegravity.sudoku.solver.HintResource;
import com.onegravity.sudoku.solver.R;
import com.onegravity.sudoku.solver.SolvingTechniquesConfig;

/**
 * @author Emanuel Moecklin
 */
final class ChainMetaInfo implements Serializable {
	private static final long serialVersionUID = 2496287324528971718L;

	final SolvingTechniquesConfig mConfig;
	final boolean mIsMultipleEnabled;
	final boolean mIsDynamic;
	final boolean mIsNishio;
	final int mLevel;
    
    /**
     * Create the engine for searching forcing chains.
     * @param isMultipleEnabled Whether multiple forcing chains (Cell and Region Forcing Chains) are searched
     * @param isDynamic Whether dynamic forcing chains are included
     * @param isNishio Whether Nishio mode is activated
     * Only used if <tt>isDynamic</tt> and <tt>isMultiple</tt> are <tt>false</tt>.
     */
    ChainMetaInfo(boolean isMultipleEnabled, boolean isDynamic, boolean isNishio, int level, SolvingTechniquesConfig config) {
        mIsMultipleEnabled = isMultipleEnabled;
        mIsDynamic = isDynamic;
        mIsNishio = isNishio;
        mLevel = level;
        mConfig = config;
    }

    boolean isDynamic() {
        return mIsDynamic;
    }

    boolean isNishio() {
        return mIsNishio;
    }

    boolean isMultiple() {
        return mIsMultipleEnabled;
    }

    public int getLevel() {
        return this.mLevel;
    }

	public SolvingTechniquesConfig getConfig() {
		return mConfig;
	}

	double getDifficulty() {
        if (mLevel >= 2) return 9.5 + 0.5 * (mLevel - 2);
        else if (mLevel > 0) return 8.5 + 0.5 * mLevel;
        else if (mIsNishio) return 7.5; // Nishio
        else if (mIsDynamic) return 8.5; // Dynamic chains
        else if (mIsMultipleEnabled) return 8.0; // Multiple chains
        else throw new IllegalStateException(); // Must compute by themselves
    }

    public String getCommonName(ChainHint hint) {
        if (!mIsDynamic && !mIsMultipleEnabled) {
            return HintResource.getString(hint.mIsXChain ? R.string.hint_xchain : R.string.hint_ychain);
        }
        return null;
    }

}